package com.zbkj.front.controller.v2;

import com.zbkj.dal.base.enums.ExpressOrderType;
import com.zbkj.dal.base.enums.ShareProfitSceneEnums;
import com.zbkj.dal.base.result.CommonResult;
import com.zbkj.dal.entity.order.MerchantOrder;
import com.zbkj.dal.entity.order.Order;
import com.zbkj.dal.entity.order.OrderDetail;
import com.zbkj.dal.entity.wechat.WechatPayInfo;
import com.zbkj.service.manager.ExpressManager;
import com.zbkj.service.manager.ShareProfitManager;
import com.zbkj.service.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

import static com.zbkj.dal.base.enums.ExpressOrderPayMethodType.SHIPPER_PAY;

@RestController
public class DevController {

    @Autowired
    private OrderService orderService;
    @Autowired
    private WechatPayInfoService wechatPayInfoService;
    @Autowired
    private OrderDetailService orderDetailService;
    @Autowired
    private WechatService wechatService;
    @Autowired
    private ExpressManager expressManager;
    @Resource
    private ShareProfitManager shareProfitManager;
    @Autowired
    private MerchantOrderService merchantOrderService;


    @GetMapping("/func1")
    public CommonResult<?> func1() {
        expressManager.createExpressOrder("PT884170860868485373194", "商品名称", SHIPPER_PAY, ExpressOrderType.PURCHASE);
        return CommonResult.success();
    }

    @GetMapping("/dev/share/profit")
    public CommonResult<Void> testShareProfit() throws Exception {
        shareProfitManager.shareProfitInitAsync(81, "SH687171118285195527648", "", new BigDecimal("1800.00"), new BigDecimal("1800.00"), ShareProfitSceneEnums.PRODUCT_LEASE_BUY);
        Thread.sleep(2000);
        shareProfitManager.shareProfitConfirmAsync("SH687171118285195527648");
        return CommonResult.success();
    }

    @GetMapping("/dev/order/express")
    public CommonResult<Void> testUploadOrderExpress(@RequestParam String orderNo) {
        Order orderInfo = orderService.getByOrderNo(orderNo);
        MerchantOrder merchantOrder = merchantOrderService.getOneByPlatOrderNo(orderNo);
        WechatPayInfo payInfo = wechatPayInfoService.getByNo(orderInfo.getOutTradeNo());
        OrderDetail orderDetail = orderDetailService.getOneByOrderNo(orderNo);
        wechatService.miniAppletOrderExpressUpload(orderInfo, merchantOrder, payInfo, orderDetail.getProductName());
        return CommonResult.success();
    }
}
